export interface MyResponseType {
	code: number | string;
	message: string;
	data: any;
	status: number;
}

import axios, { AxiosRequestConfig } from 'axios';

const instance = axios.create({
	baseURL: '/api'
});

const request = async (config: AxiosRequestConfig): Promise<MyResponseType> => {
	try {
		//@ts-ignore
		// config = { ...config, headers: { ...config.headers, 'x-session-id': window.sessionStorage.getItem('sessionID') ? window.sessionStorage.getItem('sessionID') : null } };
		const response = (await instance.request(config)) as MyResponseType;
		// data
		//   ? console.log(data) // 成功消息提示
		//   : console.error(data) // 失败消息提示
		return response;
	} catch (err) {
		return Promise.reject(err.response);
	}
};

export default request;
